package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public IPage<UserInfo> findBlackByPage(Long userId, int page, int pageSize) {
        //1.构建分页参数对象
        Page page1 = new Page(page, pageSize);
        //2.调用方法分页
        return userInfoMapper.findBlackList(page1, userId);
    }

    //移除黑名单
    @Override
    public void deleteBlackList(Long userId, Long blackId) {

        LambdaQueryWrapper<BlackList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BlackList::getBlackUserId, blackId);
        wrapper.eq(BlackList::getUserId, userId);
        //调用mapper删除
        blackListMapper.delete(wrapper);
    }
}
